using Avalonia.Controls;
using Avalonia.MusicStore.ViewModels;
using Avalonia.ReactiveUI;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace Avalonia.MusicStore.Views
{
    public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
    {
        public MainWindow()
        {
            InitializeComponent();
            this.WhenActivated(action => action(ViewModel!.ShowDialog.RegisterHandler(DoShowDialogAsync)));
        }
        // This code is only valid in newer ReactiveUI which is shipped since avalonia 11.2.0 
        private async Task DoShowDialogAsync(IInteractionContext<MusicStoreViewModel,
                                                ObservableCollection<AlbumViewModel>> interaction)
        {
            var dialog = new MusicStoreWindow();
            dialog.DataContext = interaction.Input;

            var result = await dialog.ShowDialog<ObservableCollection<AlbumViewModel>>(this);
            interaction.SetOutput(result);
        }   
    }
}